package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.AfshopSearchHistory;
import com.example.demo.mapper.AfshopSearchHistoryMapper;
import com.example.demo.service.IAfshopSearchHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 搜索历史表 服务实现类
 * </p>
 *
 * @author Mr.We
 * @since 2024-06-26
 */
@Service
public class AfshopSearchHistoryServiceImpl extends ServiceImpl<AfshopSearchHistoryMapper, AfshopSearchHistory> implements IAfshopSearchHistoryService {
    @Autowired
    private AfshopSearchHistoryMapper searchHistoryDao;

    @Override
    public AfshopSearchHistory queryObject(Integer id) {
        return searchHistoryDao.queryObject(id);
    }

    @Override
    public List<AfshopSearchHistory> queryList(Map<String, Object> map) {
        return searchHistoryDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return searchHistoryDao.queryTotal(map);
    }

    @Override
    public boolean save(AfshopSearchHistory region) {
        int result = searchHistoryDao.insert(region);
        return result > 0;
    }


    public void update(AfshopSearchHistory region) {
        QueryWrapper<AfshopSearchHistory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", region.getUserId());
        searchHistoryDao.update(queryWrapper);
    }


    public void delete(Integer id) {
        QueryWrapper<AfshopSearchHistory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        searchHistoryDao.delete(queryWrapper);
    }


    public void deleteBatch(Integer[] ids) {
        QueryWrapper<AfshopSearchHistory> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id", (Object) ids);
        searchHistoryDao.delete(queryWrapper);
    }

    @Override
    public void deleteByUserId(Long userId) {
        searchHistoryDao.deleteByUserId(userId);
    }
}
